package model.data.wrapper;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import model.data.tableModel.sale.Product;

/**
 * Wrapper class for the input that was entered in the view.
 * 
 * @version %I%, %G%
 */
public final class InputWrapper {

	private static Logger debug = LogManager.getLogger("DEBUG");
	private static Logger log = LogManager.getLogger("ERROR");

	private final Product selectedProduct;
	private int crateCount;
	private int bottleCount;
	private double value;
	private double depositCount;

	/**
	 * @param selectedProduct
	 * @param crateCount
	 * @param bottleCount
	 */
	public InputWrapper(Product selectedProduct, String crateCount, String bottleCount) {

		this.selectedProduct = selectedProduct;
		this.depositCount = 0.0;
		this.value = -1;

		try {
			if (crateCount == null || "".equals(crateCount) || "-".equals(crateCount)) {
				this.crateCount = 0;
			} else {
				this.crateCount = Integer.valueOf(crateCount);
			}
			if (bottleCount == null || "".equals(bottleCount) || "-".equals(bottleCount)) {
				this.bottleCount = 0;
			} else {
				this.bottleCount = Integer.valueOf(bottleCount);
			}
		} catch (NumberFormatException e) {
			log.error(e.getMessage());
		}
		debug.debug("New InputWrapper for product: " + selectedProduct + " was created.");
	}

	@Override
	public int hashCode() {

		final int prime = 31;
		int result = 1;
		result = prime * result + bottleCount;
		result = prime * result + crateCount;
		result = prime * result + ((selectedProduct == null) ? 0 : selectedProduct.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {

		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		InputWrapper other = (InputWrapper) obj;
		if (bottleCount != other.bottleCount)
			return false;
		if (crateCount != other.crateCount)
			return false;
		if (selectedProduct == null) {
			if (other.selectedProduct != null)
				return false;
		} else if (!selectedProduct.equals(other.selectedProduct))
			return false;
		return true;
	}
	
	/* GETTER AND SETTER BELOW */	

	public Product getSelectedProduct() {

		return selectedProduct;
	}

	public int getTrayCount() {

		return crateCount;
	}

	public int getBottleCount() {

		return bottleCount;
	}

	public void setValue(double value) {

		this.value = value;
	}

	public double getValue() {

		return value;
	}

	public double getDepositCount() {

		return depositCount;
	}

	public void setDepositCount(double depositCount) {

		this.depositCount = depositCount;
	}
}
